#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "LED.h"
#include "Store.h"
#include "Delay.h"
#include "Key.h"


int main(void)
{
	uint8_t KeyNum;
	OLED_Init();
	LED_Init();
	Store_Init();
	Key_Init();
	
//	// 读取测试
//	OLED_ShowHexNum(1, 1, MyFLASH_ReadByte(0x08000000), 2);			// 8位
//	OLED_ShowHexNum(2, 1, MyFLASH_ReadHalfWord(0x08000000), 4);		// 16位
////	OLED_ShowHexNum(2, 1, MyFLASH_ReadHalfWord(0x08000002), 4);
////	OLED_ShowHexNum(2, 1, MyFLASH_ReadHalfWord(0x08000001), 4);		//字, 半字的地址关系
//																	// 地址加1, 数据往前跳两个
//	OLED_ShowHexNum(3, 1, MyFLASH_ReadWord(0x08000000), 8);			// 32位
////	OLED_ShowHexNum(3, 1, MyFLASH_ReadWord(LastPage + 16), 8);			

//	// 擦除测试
////	Delay_ms(2000);
////	MyFlashErasePage(0x08000000);
////	Delay_ms(2000);
////	MyFLASH_EraseAllPages();
////	
////	LED1_ON();														// 确实如此, 程序擦除了, 这里也不亮了

//	// 写入测试
//	MyFlashErasePage(LastPage);		// 写入前要先擦除
//	MyFLASH_ProgramWord(LastPage, 0x12345678);
//	MyFLASH_ProgramWord(LastPage + 16, 0xABCD);

	while(1)
	{
		KeyNum = Key_GetNum();
		if (KeyNum == 1)
		{
			Store_Data[1] = 0x1234;
			Store_Data[2] = 0x5678;
			Store_Save();
		}
		
		if (KeyNum == 2)
		{
			Store_Clear();
		}
	}
}
